The invention relates to the field of electronic computers, and more particularly, to the control of computer operation by instructions of object-based programs. In a specific application, the invention relates to methods and apparatus for synchronizing concurrent and cooperative threads.
Computers operate under the control of programmed instructions. Computer programmers typically write computer programs as source code in an alpha-numeric text format that a skilled person can relatively-easily read and understand. Other programs, including compilers, convert these text-files into binary machine-language instructions which will directly control a computer's central processing unit ("CPU"). Each model (or series) of computer typically has a unique set of machine-language instructions dictated by the hardware design of the CPU, and compilers and interpreters typically convert a source code program to the machine-language instructions of a particular model (or series) of computer.
Standard programming languages have developed so that different programmers can write programs independently of the machine code instructions of the computer on which the program will ultimately run. An object-based programming language supports objects as a language feature. An object has a set of "operations" and a "state" that remembers the effect of the operations. Objects may be contrasted with functions, which have no memory. Function values are completely determined by their arguments, and are precisely the same for each invocation. In contrast, the value returned by an operation on an object may depend on the object's state as well as the operation's arguments. An object may learn from experience, its reaction to an operation being determined by its invocation history. Further background information regarding object-based language can be found in "Dimensions of Object-Based Language Design," by Peter Wegner, presented at OOPSLA'87, Object-Oriented Programming Systems, Languages and Applications, pp. 168-182, Orlando, Fla., October, 1987 (proceedings published by Association for Computing Machinery, Inc., New York, N.Y.).
A "thread" is a single sequential flow of control within a program. A thread has its own execution stack where method activations reside. When a method is activated, an activation is "pushed" onto the stack. The activation is "popped" when the method returns. Since one activation can activate another method, the stack has first-in-last-out behavior. In a system, threads can either be "cooperative" or "concurrent". Threads are said to be "cooperative" if only one thread has total control until it voluntary relinquishes control. Threads are said to be "concurrent" if they are not cooperative.
In an object-based program, a thread may execute processes that involve multiple objects. Similarly, multiple threads may attempt to execute processes that involve a single object. It is desirable, at times, to prevent all but one thread from executing a process that involves a particular object. An object will be said here to be "locked" when only one thread is permitted to operate on that object, and an object will be said to be "unlocked" otherwise. A thread will be said to hold a lock on an object if it is the only thread permitted to operate on that object. Thread synchronization will be said to be a process by which threads interact to (1) check the status of objects (as locked or unlocked), (2) obtain and remove locks, and (3) avoid operations on locked objects (except for the thread that holds a lock on an object).
One object-based language that seeks to support synchronization is "JAVA". "JAVA" has been defined according to a high-level syntax and semantics. See "The Java Language Specification", by James Gosling, Bill Joy, and Guy Steele, ISBN 0-201-63455-4 and "The Java Virtual Machine Specification", by Tim Lindholm and Frank Yellin, ISBN 0-201-63452-X. However, such high level definitions and descriptions do not completely specify compilers and or interpreters needed to run "JAVA" programs on real platforms. In particular, the high-level definitions and descriptions do not describe particular methods for thread synchronization and object locking.